import { ref } from 'vue'
import { tnNavPage } from '@tuniao/tnui-vue3-uniapp/utils'
import type { Banner } from '@/types/api/banner'
import type { IndexPageOnLoadFunc } from '@/pages/index/types'
import type { Article } from '@/types/api/article'
import { useSubPageProvide } from '@/pages/index/composables'
import { generateRandomNumber } from '@/utils/local-mock'

export const useSubPage = () => {
  // 轮播数据
  const swiperData = ref<Banner[]>([])
  // 资讯数据
  const newsData = ref<Article[]>([])
  // 状态栏高度
  const statusBarHeight  = ref<string>('0px')

  // 跳转到资讯详情页
  const navArticleDetail = (id: string) => {
    tnNavPage(`/detail-page/article-detail/index?id=${id}&type=news`)
  }

  const onLoad: IndexPageOnLoadFunc = () => {
	  
	const systemInfo = uni.getSystemInfoSync();  
	statusBarHeight.value = systemInfo.statusBarHeight + 'px'
	  
    swiperData.value = [
      {
        id: '1',
        name: '轮播图1',
        image: 'https://resource.tuniaokj.com/images/swiper/ad1.jpg',
        title: 'Demo测试',
        desc: '定额4-11-4-5涂沥青(防水层)是按几遍做法考虑的',
      },
      {
        id: '2',
        name: '轮播图2',
        image: 'https://resource.tuniaokj.com/images/swiper/ad2.jpg',
        title: 'Demo测试',
        desc: '混凝土防撞护栏组价',
      },
      {
        id: '3',
        name: '轮播图3',
        image: 'https://resource.tuniaokj.com/images/swiper/ad3.jpg',
        title: 'Demo北北',
        desc: '福建省运费规定',
      },
      {
        id: '4',
        name: '轮播图4',
        image: 'https://resource.tuniaokj.com/images/swiper/ad4.jpg',
        title: 'Demo猪猪',
        desc: '努力成为大佬',
      },
    ]

    newsData.value = [{
		id: generateRandomNumber(1000, 9999).toString(),
		title: '招标文件结构异常！',
		mainImage: 'https://images.669pic.com/element_min_new_pic/35/59/77/8/fb8a38e729cc89b95d89ec429062e43e.png',
		desc: '原因：造价文件导出时生成的节点对应关系错误；解决方案：招标业主或招标代理重新导出招标文件',
		content: '招标文件结构异常！',
		tags: ['招标文件'],
		hotCount: generateRandomNumber(1, 100),
		replyCount: generateRandomNumber(1, 100),
		likeCount: generateRandomNumber(1, 100),
		viewCount: generateRandomNumber(1, 100),
		shareCount: generateRandomNumber(1, 100),
		viewUsersAvatar: [],
		recommend: generateRandomNumber(1, 10) % 2 === 0,
	}, {
		id: generateRandomNumber(1000, 9999).toString(),
		title: 'eccG是什么文件呢？',
		mainImage: 'https://images.669pic.com/element_min_new_pic/35/59/77/8/fb8a38e729cc89b95d89ec429062e43e.png',
		desc: 'eccG是什么文件呢？',
		content: 'eccG是什么文件呢？',
		tags: ['招标文件'],
		hotCount: generateRandomNumber(1, 100),
		replyCount: generateRandomNumber(1, 100),
		likeCount: generateRandomNumber(1, 100),
		viewCount: generateRandomNumber(1, 100),
		shareCount: generateRandomNumber(1, 100),
		viewUsersAvatar: [],
		recommend: generateRandomNumber(1, 10) % 2 === 0,
	}, {
		id: generateRandomNumber(1000, 9999).toString(),
		title: '5-1-5-8 定额 振动标线 100m2 0.405 false 0.0 06.构造物Ⅰ 4876',
		mainImage: 'https://images.669pic.com/element_min_new_pic/35/59/77/8/fb8a38e729cc89b95d89ec429062e43e.png',
		desc: '复制定额到其他清单项后，工程量计算式不见了，这个怎么处理呢？',
		content: '5-1-5-8 定额 振动标线 100m2 0.405 false 0.0 06.构造物Ⅰ 4876',
		tags: ['定额'],
		hotCount: generateRandomNumber(1, 100),
		replyCount: generateRandomNumber(1, 100),
		likeCount: generateRandomNumber(1, 100),
		viewCount: generateRandomNumber(1, 100),
		shareCount: generateRandomNumber(1, 100),
		viewUsersAvatar: [],
		recommend: generateRandomNumber(1, 10) % 2 === 0,
	}, {
		id: generateRandomNumber(1000, 9999).toString(),
		title: '公路项目材料调差取费问题',
		mainImage: 'https://images.669pic.com/element_min_new_pic/35/59/77/8/fb8a38e729cc89b95d89ec429062e43e.png',
		desc: '公路项目材料调差 因为是除税价调差汇总 除了再记一次营改增的税点，是否还有其他费用要取，比如安全、环保费用？陕西地区是否有相关文件？',
		content: '',
		tags: ['业务咨询'],
		hotCount: generateRandomNumber(1, 100),
		replyCount: generateRandomNumber(1, 100),
		likeCount: generateRandomNumber(1, 100),
		viewCount: generateRandomNumber(1, 100),
		shareCount: generateRandomNumber(1, 100),
		viewUsersAvatar: [],
		recommend: generateRandomNumber(1, 10) % 2 === 0,
	}, {
		id: generateRandomNumber(1000, 9999).toString(),
		title: '如何录入基本预备费',
		mainImage: 'https://images.669pic.com/element_min_new_pic/35/59/77/8/fb8a38e729cc89b95d89ec429062e43e.png',
		desc: '如何录入基本预备费',
		content: '',
		tags: ['预算书'],
		hotCount: generateRandomNumber(1, 100),
		replyCount: generateRandomNumber(1, 100),
		likeCount: generateRandomNumber(1, 100),
		viewCount: generateRandomNumber(1, 100),
		shareCount: generateRandomNumber(1, 100),
		viewUsersAvatar: [],
		recommend: generateRandomNumber(1, 10) % 2 === 0,
	}, {
		id: generateRandomNumber(1000, 9999).toString(),
		title: '40m以内的墩桩要不要计提升模架',
		mainImage: 'https://images.669pic.com/element_min_new_pic/35/59/77/8/fb8a38e729cc89b95d89ec429062e43e.png',
		desc: '40m以内的墩桩要不要计提升模架',
		content: '',
		tags: ['其他'],
		hotCount: generateRandomNumber(1, 100),
		replyCount: generateRandomNumber(1, 100),
		likeCount: generateRandomNumber(1, 100),
		viewCount: generateRandomNumber(1, 100),
		shareCount: generateRandomNumber(1, 100),
		viewUsersAvatar: [],
		recommend: generateRandomNumber(1, 10) % 2 === 0,
	}, {
		id: generateRandomNumber(1000, 9999).toString(),
		title: '陕西公路工程人工预算单价',
		mainImage: 'https://images.669pic.com/element_min_new_pic/35/59/77/8/fb8a38e729cc89b95d89ec429062e43e.png',
		desc: '陕西目前最新公路工程人工费是多少，为什定额价是106.28，预算价是105.89？',
		content: '',
		tags: ['取费程序'],
		hotCount: generateRandomNumber(1, 100),
		replyCount: generateRandomNumber(1, 100),
		likeCount: generateRandomNumber(1, 100),
		viewCount: generateRandomNumber(1, 100),
		shareCount: generateRandomNumber(1, 100),
		viewUsersAvatar: [],
		recommend: generateRandomNumber(1, 10) % 2 === 0,
	}, {
		id: generateRandomNumber(1000, 9999).toString(),
		title: '陕西省砂石填方怎么套定额',
		mainImage: 'https://images.669pic.com/element_min_new_pic/35/59/77/8/fb8a38e729cc89b95d89ec429062e43e.png',
		desc: '陕西省砂石填方怎么套定额？',
		content: '',
		tags: ['预算书'],
		hotCount: generateRandomNumber(1, 100),
		replyCount: generateRandomNumber(1, 100),
		likeCount: generateRandomNumber(1, 100),
		viewCount: generateRandomNumber(1, 100),
		shareCount: generateRandomNumber(1, 100),
		viewUsersAvatar: [],
		recommend: generateRandomNumber(1, 10) % 2 === 0,
	}]
	// Array.from({ length: generateRandomNumber(10, 30) }).map(
 //      () => ({
 //        id: generateRandomNumber(1000, 9999).toString(),
 //        title: 'DemoAPP模板全新上线',
 //        mainImage: 'https://images.669pic.com/element_min_new_pic/35/59/77/8/fb8a38e729cc89b95d89ec429062e43e.png',
 //        desc: 'DemoAPP模板全新上线，欢迎大家前来体验。',
 //        content: 'DemoAPP模板全新上线，欢迎大家前来体验。',
 //        tags: ['DemoAPP'],
 //        hotCount: generateRandomNumber(1, 100),
 //        replyCount: generateRandomNumber(1, 100),
 //        likeCount: generateRandomNumber(1, 100),
 //        viewCount: generateRandomNumber(1, 100),
 //        shareCount: generateRandomNumber(1, 100),
 //        viewUsersAvatar: [],
 //        recommend: generateRandomNumber(1, 10) % 2 === 0,
 //      })
 //    )
  }

  useSubPageProvide(3, {
    onLoad,
  })

  return {
	  statusBarHeight,
    swiperData,
    newsData,
    navArticleDetail,
  }
}
